<?php
/**
 * Created by LíJimpéy(：
 * User: jimpey88
 * Date: 2024/3/26
 * Email: < jimpey@qq.com >
 * Project: company-admin-tp6
 */


namespace app\backend_api\middleware;

use Closure;
use think\facade\Lang;
use think\facade\Request;

class Translate
{

    /**
     * @param Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $lang = $request->header('Accept-Language');

        if ($lang) {
            switch ($lang) {
                case 'cn':
                    $lang = 'zh-cn';
                    break;
                case 'en':
                    $lang = 'en-us';
                    break;
                default:
                    break;
            }
            Lang::setLangSet($lang);
        }

        return $next($request);
    }
}
